Questions
2 of 25
1How do you build a reusable pagination and sorting query DTO that can be extended by feature-specific DTOs in NestJS?
2How do you use ClassSerializerInterceptor with @Exclude() and @Expose() to control response shape in NestJS?
3What versioning strategies does NestJS support and how do you enable versioning?
4How do you implement idempotency keys for POST requests to prevent duplicate operations in NestJS?
5How do you implement API rate limiting per user or per IP in NestJS?
6How do you handle raw body access for webhook signature verification in NestJS?
7How do you stream a large file or dataset as a response without loading it fully into memory in NestJS?
8How do you implement content negotiation so an endpoint returns JSON or CSV based on the Accept header in NestJS?
9How do you set a default version so unversioned requests are handled by a specific version in NestJS?
10How do you document DTO properties for Swagger and handle optional vs required fields in NestJS?
11How do you handle HATEOAS hypermedia links in NestJS REST responses?
12What decorators does NestJS provide for route parameters and how do they differ from query params?
13How do you handle a route where the param can be either a numeric ID or the literal string 'me' in NestJS?
14How do you handle multi-value query parameters (arrays) in NestJS?
15What is the difference between @Body(), @Body('field'), and using a full DTO class in NestJS?
16How do you implement a PATCH endpoint correctly with partial validation using PartialType in NestJS?
17How do you implement discriminated union body validation where the DTO shape depends on a type field in NestJS?
18How do you set HTTP status codes, response headers, and redirects in NestJS without using @Res()?
19What is the recommended file structure for versioned controllers in a NestJS project?
20How do wildcard and optional route segments work in NestJS?
21What is the difference between @Param('id') and @Param() with no argument in NestJS?
22How do you extract and type query parameters in NestJS including optional ones with defaults?
23How do you implement a standard paginated response envelope across all list endpoints in NestJS?
24How do you apply versioning at controller and method level in NestJS and how do you mark a route as version-neutral?
25How do you set up Swagger in a NestJS application and annotate your controllers?
02 / 25

How do you use ClassSerializerInterceptor with @Exclude() and @Expose() to control response shape in NestJS?

Enable ClassSerializerInterceptor globally so it calls instanceToPlain() on every response. Decorate entity fields with @Exclude() to omit sensitive data and @Expose() for whitelist mode. Controllers must return class instances — returning plain objects bypasses the serialization decorators entirely.

ClassSerializerInterceptor with exclusion rules
ClassSerializerInterceptor requirements:
  1. 1

    Controllers must return class instances — plain objects have no metadata for the interceptor to read.

  2. 2

    @Exclude() — blacklist approach: all properties included by default, decorated ones are stripped.

  3. 3

    @Expose() with excludeExtraneousValues: true — whitelist approach: only decorated properties are included.

  4. 4

    @SerializeOptions() at route or controller level overrides the global interceptor configuration.

  5. 5

    ClassSerializerInterceptor must be registered via APP_INTERCEPTOR for DI support (e.g. injecting Reflector).

Difficulty: 5/10
Topics: ClassSerializerInterceptor, Exclude/Expose decorators, DTO shaping

Scenario Questions

0-2 years experience
  1. 1

    We have a simple NestJS controller returning a User entity. How would you use ClassSerializerInterceptor together with @Exclude() and @Expose() to ensure the password field is never sent in the response?

  2. 2

    If you add @Expose({ name: 'fullName' }) to a getter in a DTO, what will the JSON output look like when the interceptor is applied?

  3. 3

    What happens if you forget to enable the interceptor globally but still use @Exclude() on a property?

2-5 years experience
  1. 1

    You need to return different fields for admin vs regular users from the same endpoint. How could you configure ClassSerializerInterceptor and the decorators to handle this without writing separate DTOs?

  2. 2

    During a code review you notice that a nested object is still exposing its internal id even though @Exclude() is on the property. What could cause this and how would you debug it?

  3. 3

    We introduced a new optional field in a DTO and want it omitted when undefined. How does ClassSerializerInterceptor treat undefined values with @Expose()? Explain any configuration needed.

5-8 years experience
  1. 1

    Our microservice returns large payloads with many nested objects. Discuss the performance implications of using ClassSerializerInterceptor at scale and any strategies to mitigate overhead.

  2. 2

    We are migrating a legacy codebase that manually maps entities to plain objects. How would you design a migration plan to adopt ClassSerializerInterceptor and @Exclude/@Expose across multiple modules while minimizing risk?

  3. 3

    When integrating with GraphQL, we need to hide certain fields only for specific roles. How would you extend or customize ClassSerializerInterceptor to support role‑based field exclusion?

8+ years experience
  1. 1

    At the organization level we want a consistent serialization policy across dozens of services. What architectural guidelines would you set for using ClassSerializerInterceptor, and how would you enforce them across teams?

  2. 2

    Consider a scenario where a new compliance requirement mandates that PII fields be redacted in logs but still sent to trusted downstream services. How would you adapt the interceptor or decorators to satisfy this dual requirement without code duplication?

  3. 3

    If we need to support versioned APIs where field names change over time, how would you leverage @Expose({ name: ... }) and interceptor configuration to manage multiple versions while keeping a single source of truth?

Follow-up Questions

  • Can you walk me through the steps you’d take to add the interceptor to an existing controller?
  • What trade‑offs might you consider when deciding between using decorators versus manual mapping?
  • How would you test that the serialization behaves correctly for different user roles?